micro: Handle +/text search text from args#3767
micro: Handle +/text search text from args#3767JoeKar merged 1 commit intomicro-editor:masterfrom luca020400:luca/plusslash
Conversation
Andriamanitra
left a comment
There was a problem hiding this comment.
I think NewBufferFromFileWithCommand is a weird API to have because it's coupled to how the CLI works. It also requires changing all the call sites. Do you think it would be feasible to keep NewBufferFromFileAtLoc/NewBuffer as-is and handle moving the cursor to a match separately?
|
That's possible, but it's not that different from the current API as a whole, it would be equivalent to simply adding searchText parameter (as start location was only used for CLI already) And if I split open & match i'd be weird to handle the save cursor option and furthermore the onBufferOpen would run before finding matches, and now you'd have start position (either from +lin:col for filename), onBufferOpen and then match, it would be very confusing to me... Feel free to propose something, but this seemed the "sanest" model to implement to me |
That was my first though too, but after a closer look, it looks like quite a sane generalization of
Potentially we might use this concept of "command" not just in the CLI but also in some other cases at runtime, like it is used in vim (and vi, ed, sed...). |
|
Ping? |
|
@JoeKar what do you think about merging this? |
No bad idea and...
...we're able to extend the What I'm struggling with is the fact, that |
Are they? I don't think we export it to lua.
But here we don't pass any user input (or any other non-constant input) to |
I admit I'm not particularly aware of how plugins work, but I don't expect go functions to be directly callable from there? That's why I removed it as I assumed it wasn't exported.
But isn't that more of an architectural issue? |
You're right. It can't be accessed.
You're right again. Here we only search for the search string within the arguments. The user string will cause problems at the same location as in #3700 (with
At least a bad design decision, in case the "wrong"
More or less yes. Some corner cases will actually lead to a crash (see linked issue). |
|
Can this be merged? |
|
We can merge it in case @dmaluka doesn't disagree. |
|
LGTM (I think I already approved this PR a while ago), except the following (echoing the discussion and outcome of #3812):
--- a/cmd/micro/micro.go
+++ b/cmd/micro/micro.go
@@ -48,7 +48,7 @@ var (
func InitFlags() {
// Note: keep this in sync with the man page in assets/packaging/micro.1
flag.Usage = func() {
- fmt.Println("Usage: micro [OPTION]... [FILE]... [+LINE[:COL]]")
+ fmt.Println("Usage: micro [OPTION]... [FILE]... [+LINE[:COL]] [+/REGEX]")
fmt.Println(" micro [OPTION]... [FILE[:LINE[:COL]]]... (only if the `parsecursor` option is enabled)")
fmt.Println("-clean")
fmt.Println(" \tClean the configuration directory and exit")
diff --git a/assets/packaging/micro.1 b/assets/packaging/micro.1
index dbd2cc80..909bbde6 100644
--- a/assets/packaging/micro.1
+++ b/assets/packaging/micro.1
@@ -1,11 +1,12 @@
-.TH micro 1 "2025-08-16"
+.TH micro 1 "2025-09-03"
.SH NAME
micro \- A modern and intuitive terminal-based text editor
.SH SYNOPSIS
.B micro
.RI [ OPTION ]...\&
.RI [ FILE ]...\&
-.RI [+ LINE [: COL ]]
+.RI [+ LINE [: COL ]]\&
+.RI [+/ REGEX ]
.br
.B micro
.RI [ OPTION ]...\&
@@ -40,6 +41,11 @@ Specify a custom location for the configuration directory
Specify a line and column to start the cursor at when opening a buffer
.RE
.PP
+.RI +/ REGEX
+.RS 4
+Specify a regex to search for when opening a buffer
+.RE
+.PP
.B \-options
.RS 4
Show all options help and exit |
This is a feature found in vim and commonly used by Linux kernel test robots to give context about warnings and/or failures. e.g. vim +/imem_size +623 drivers/net/ipa/ipa_mem.c The order in which the commands appear in the args determines in which order the "goto line:column" and search will be executed.
|
Done, I hope the man changes are good, I don't know the syntax at all |
This is a feature found in vim and commonly used
by Linux kernel test robots to give context about
warnings and/or failures.
e.g. vim +/imem_size +623 drivers/net/ipa/ipa_mem.c
The order in which the commands appear in the args
determines the order in which the "goto line:column"
and search text will be executed.